//
//  StrategyInspectorController.m
//  StrategyInspector
//
//  Created by jiro on 12/07/21.
//  Copyright 2012 jiro music. All rights reserved.
//

#import "StrategyInspectorController.h"

#import "Constants.h"
#import "../Commons.h"
//#import "Strategy005.h"

@implementation StrategyInspectorController

@synthesize fxInvestmentBasicParameterController;

- (void) windowDidLoad
{	
	//	---- init
	[ strategyButton removeAllItems ];
//	[ strategyButton addItemWithTitle: [ Strategy005 name ] ];

	[ timeUnitButton removeAllItems ];
	for ( int i = 0; i < TimeUnit::Type_Count - 1; i++ )
	{
		[ timeUnitButton addItemWithTitle: TimeUnit::toString( ( TimeUnit::Type ) i  ) ];
	}
	[ timeUnitButton selectItemAtIndex: 3 ];	

	[ priceTypeButton removeAllItems ];
	for ( int i = 0; i < PriceField::Type_Count; i++ )
	{
		[ priceTypeButton addItemWithTitle: PriceField::toString( static_cast< PriceField::Type >( i ) ) ];
	}
	//	----
}

- (void) inspectAsyncFunc: (void*) arg
{
/*
	id menuItem = [ currencyExchangeTypeButton selectedItem ];
	FxInvestmentBasicParameter* basicParam = [ fxInvestmentBasicParameterController parameter ];

	StrategyInspectionParameter005* inspectParam = [ [ StrategyInspectionParameter005 alloc ] init ]; 
	inspectParam.startDate = [ startDatePicker dateValue ];
	inspectParam.endDate = [ endDatePicker dateValue ];
	inspectParam.currencyCode = [ [ menuItem title ] substringWithRange: NSMakeRange( 0, 3 ) ];
	inspectParam.targetCurrencyCode = [ [ menuItem title ] substringWithRange: NSMakeRange( 4, 3 ) ];
	inspectParam.targetSettlementGap = [ targetSettlementGapField doubleValue ];
	inspectParam.lossCutGap = [ lossCutGapField doubleValue ];
	inspectParam.timeUnitSec = TimeUnit::seconds( TimeUnit::toType( [ [ timeUnitButton selectedItem ] title ] ) );
	inspectParam.shortTermMaLength = inspectParam.timeUnitSec * [ shortTermMaField doubleValue ];
	inspectParam.middleTermMaLength = inspectParam.timeUnitSec * [ middleTermMaField doubleValue ];
	inspectParam.priceFieldType = PriceField::toType( [ [ priceTypeButton selectedItem ] title ] );
	inspectParam.timeUnitSec = TimeUnit::seconds( TimeUnit::toType( [ [ timeUnitButton selectedItem ] title ] ) );

	StrategyInspectionResult* result = [ Strategy005
		inspectWithParam: basicParam
		andInspectParam: inspectParam ];
//	NSLog( @"%@", result );

	[ tradeCountField setStringValue: [ NSString stringWithFormat: @"%@%d", NSLocalizedString( @"trade count: ", @"" ), result.tradeCount ] ];
	[ winRateField setStringValue: [ NSString stringWithFormat: @"%@%f", NSLocalizedString( @"win rate: ", @"" ), result.winRate ] ];
	[ interestRateField setStringValue: [ NSString stringWithFormat: @"%@%f", NSLocalizedString( @"interest rate: ", @"" ), result.interestRate ] ];
	[ profitPerTradeField setStringValue: [ NSString stringWithFormat: @"%@%f", NSLocalizedString( @"profit per trade: ", @"" ), result.profitPerTrade ] ];
	[ timeIntervalPerTradeField setStringValue: [ NSString stringWithFormat: @"%@%f(day)", NSLocalizedString( @"time interval per trade: ", @"" ), result.timeIntervalPerTradeDay ] ];

	[ progressIndicator stopAnimation: self ];
	[ inspectButton setEnabled: YES ];
*/
} 

- (void) inspect: (id) sender
{
	[ inspectButton setEnabled: NO ];
	[ progressIndicator startAnimation: self ];
	[ NSThread detachNewThreadSelector: @selector( inspectAsyncFunc: ) toTarget: self withObject: nil ];
}

@end
